home *** CD-ROM | disk | FTP | other *** search
/ World of Video / World of Video.iso / gfxprograms / 3dprograms / rayshade-4.0 / raypaint / glgraphics.c < prev    next >
C/C++ Source or Header  |  1995-02-13  |  3KB  |  157 lines

  1. /*
  2.  * glgraphics.c
  3.  *
  4.  * Copyright (C) 1989, 1991 Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  * 
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * glgraphics.c,v 4.1 1994/08/09 08:06:21 explorer Exp
  17.  *
  18.  * glgraphics.c,v
  19.  * Revision 4.1  1994/08/09  08:06:21  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:27  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  17:36:39  kolb
  26.  * Initial version.
  27.  * 
  28.  * 
  29.  */
  30.  
  31. #include <gl.h>
  32. #include <device.h>
  33.  
  34. #define CPACK(x)    cpack(((((x)[2] << 8) | (x)[1]) << 8) | x[0])
  35.  
  36. GraphicsInit(xsize, ysize, name)
  37. int xsize, ysize;
  38. char *name;
  39. {
  40. #ifndef _IBMR2
  41.     foreground();
  42. #endif
  43.     prefsize(xsize, ysize);
  44.     winopen(name);
  45.     ortho2(-0.5, (float)xsize -0.5, -0.5, (float)ysize - 0.5);
  46.     viewport(0, xsize -1, 0, ysize -1);
  47.     color(BLACK);
  48.     clear();
  49.     RGBmode();
  50.     gconfig();
  51.     unqdevice(INPUTCHANGE);
  52.     qdevice(LEFTMOUSE);  /* Pop a square on request */
  53.     qdevice(MIDDLEMOUSE);
  54.     qdevice(RIGHTMOUSE);
  55.     qdevice(REDRAW);
  56. }
  57.  
  58. /*
  59.  * Draw the pixel at (xp, yp) in the color given by the rgb-triple,
  60.  * 0 indicating 0 intensity, 255 max intensity.
  61.  */
  62. GraphicsDrawPixel(xp, yp, color)
  63. int xp, yp;
  64. unsigned char color[3];
  65. {
  66.     unsigned long int pix;
  67.  
  68.     pix = (((color[2] << 8) | color[1]) << 8) | color[0];
  69.     lrectwrite(xp, yp, xp, yp, &pix);
  70. }
  71.  
  72. /*
  73.  * Draw the rectangle with lower left corner (xp, yp) and upper right
  74.  * corner (xp+ys, yp+ys).  The colors of the l-l, l-r, u-r, and u-l
  75.  * corners are given as arrays of unsigned chars as above.
  76.  */
  77. GraphicsDrawRectangle(xp, yp, xs, ys, ll, lr, ur, ul)
  78. int xp, yp, xs, ys;
  79. unsigned char ll[3], lr[3], ur[3], ul[3];
  80. {
  81.     int   p[2];
  82.  
  83. #if defined(_IBMR2) && !defined(SHARED_EDGES)
  84.     /*
  85.      * RS6000 doesn't seem to draw lower and left edges
  86.      * of rectangles correctly.
  87.      */
  88.     xp--; yp--;
  89.     xs++; ys++;
  90. #endif
  91.     bgnpolygon();
  92.  
  93.     p[0] = xp; p[1] = yp;
  94.     CPACK(ll);
  95.     v2i(p);
  96.  
  97.     p[0] += xs;
  98.     CPACK(lr);
  99.     v2i(p);
  100.  
  101.     p[1] += ys;
  102.     CPACK(ur);
  103.     v2i(p);
  104.     
  105.     p[0] = xp;
  106.     CPACK(ul);
  107.     v2i(p);
  108.  
  109.     endpolygon();
  110. }
  111.  
  112. GraphicsLeftMouseEvent()
  113. {
  114.     /*
  115.      * Return TRUE if left mouse button is down.
  116.      */
  117.     return getbutton(LEFTMOUSE);
  118. }
  119.  
  120. GraphicsMiddleMouseEvent()
  121. {
  122.     return getbutton(MIDDLEMOUSE);
  123. }
  124.  
  125. GraphicsRightMouseEvent()
  126. {
  127.     return getbutton(RIGHTMOUSE);
  128. }
  129.  
  130. /*
  131.  * Return position of mouse in unnormalized screen coordinates.
  132.  */
  133. GraphicsGetMousePos(x, y)
  134. int *x, *y;
  135. {
  136.     int xo, yo;
  137.  
  138.     getorigin(&xo, &yo);
  139.     *x = getvaluator( MOUSEX ) - xo;
  140.     *y = getvaluator( MOUSEY ) - yo;
  141. }
  142.  
  143. GraphicsRedraw()
  144. {
  145.     Device dev;
  146.     short val;
  147.  
  148.     while (qtest()) {
  149.         dev = qread(&val);
  150.         if (dev == REDRAW) {
  151.             reshapeviewport();
  152.             return TRUE;
  153.         }
  154.     }
  155.     return FALSE;
  156. }
  157.